#include <iostream>
#include <iostream>
#include "Dlist.h"
#include "Array.h"

using namespace std;

int main() {

	bool cont	= true;			// trigger to stop loop
	unsigned int c;

	Container_t<int>* test;
	int i = 0;
	cout << "	0: class Dlist" << endl
		 << "	1: class Array" << endl;
	cin >> c;
	if(c) {
		test = (Container_t<int> *)new Array_t<int>();
	} else {
		test = new Dlist_t<int>();
	}
	while (cont) {
		cout << "	0: insert" 	<< endl
			 << "	1: append" 	<< endl
			 << "	2: prepend" << endl
			 << "	3: find" 	<< endl
			 << "	4: remove" 	<< endl
			 << "	5: count" 	<< endl
			 << "Enter your choice : << endl" << endl
			 << "(Other APIs are implemented but are not in the ui)";
		cin >> c;
		int* pi;
		switch (c) {
			case 0:
				pi = new int(i);
				test->insert(pi);
				++i;
				break;
			case 1:
				cout << "Enter index : "; 
				cin >> c;
				pi = new int(i);
				try {
					test->append(pi,int(c));
				} catch(std::string str){
					cout << str << std::endl;
					break;
				}
				++i;
				break;
			case 2:
				cout << "Enter index : "; 
				cin >> c;
				pi = new int(i);
				try {
					test->prepend(pi,int(c));
				} catch(std::string str){
					cout << str << std::endl;
					break;
				}

				++i;
				break;
			case 3:
				pi = test->find(i);	
				cout << pi << std::endl;
				break;
			case 4:
				cout << "Enter element value to remove : "; 
				cin >> c;
				pi = test->remove(int(c));
				cout << pi << std::endl;
				
				break;
			case 5:
				cout << test->count() << std::endl;
				break;
			default : cont = false;
		}
	}
	test->removeAndDeleteAll();
	return 0;
}